/*
 * @Author: 13177709051 3506463075@qq.com
 * @Date: 2024-10-31 21:16:13
 * @LastEditors: 13177709051 3506463075@qq.com
 * @LastEditTime: 2024-10-31 22:54:32
 * @FilePath: /linux28/BlockQueue/main.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "BlockQueue.hpp"
#include "Task.hpp"
#include <pthread.h>
#include <ctime>
#include <unistd.h>

void *Consumer(void *args)
{
    BlockQueue<task_t> *bp = static_cast<BlockQueue<task_t> *>(args);
    while(true)
    {
        //1. 获取数据
        task_t t;
        bp->Pop(&t);
        //2. 处理数据
        t();
    }
}

void *Productor(void *args)
{
    BlockQueue<task_t> *bq = static_cast<BlockQueue<task_t> *>(args);
    while(true)
    {
        bq->Equeue(Download);
        std::cout << "Productor -> Download" << std::endl;
        sleep(1);
    }
}

int main()
{
    BlockQueue<task_t> *bp = new BlockQueue<task_t>();
    pthread_t c1, c2, p1, p2, p3;
    pthread_create(&c1, nullptr, Consumer, bp);
    pthread_create(&c2, nullptr, Consumer, bp);
    pthread_create(&p1, nullptr, Productor, bp);
    pthread_create(&p2, nullptr, Productor, bp);
    pthread_create(&p3, nullptr, Productor, bp);

    pthread_join(c1, nullptr);
    pthread_join(c2, nullptr);
    pthread_join(p1, nullptr);
    pthread_join(p2, nullptr);
    pthread_join(p3, nullptr);

    return 0;
}